package com.bigdata.service.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import cn.dev33.satoken.annotation.SaIgnore;
import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.bigdata.common.annotation.RepeatSubmit;
import com.bigdata.common.annotation.Log;
import com.bigdata.common.core.controller.BaseController;
import com.bigdata.common.core.domain.PageQuery;
import com.bigdata.common.core.domain.R;
import com.bigdata.common.core.validate.AddGroup;
import com.bigdata.common.core.validate.EditGroup;
import com.bigdata.common.core.validate.QueryGroup;
import com.bigdata.common.enums.BusinessType;
import com.bigdata.common.utils.poi.ExcelUtil;
import com.bigdata.service.domain.vo.DatasetsVo;
import com.bigdata.service.domain.bo.DatasetsBo;
import com.bigdata.service.service.IDatasetsService;
import com.bigdata.common.core.page.TableDataInfo;

/**
 * 数据集主
 *
 * @author ruoyi
 * @date 2025-07-15
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/service/datasets")
public class DatasetsController extends BaseController {

    private final IDatasetsService iDatasetsService;

    /**
     * 查询数据集主列表
     */
    @SaCheckPermission("service:datasets:list")
    @GetMapping("/list")
    public TableDataInfo<DatasetsVo> list(DatasetsBo bo, PageQuery pageQuery) {
        return iDatasetsService.queryPageList(bo, pageQuery);
    }



    /**
     * 导出数据集主列表
     */
    @SaCheckPermission("service:datasets:export")
    @Log(title = "数据集主", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(DatasetsBo bo, HttpServletResponse response) {
        List<DatasetsVo> list = iDatasetsService.queryList(bo);
        ExcelUtil.exportExcel(list, "数据集主", DatasetsVo.class, response);
    }

    /**
     * 获取数据集主详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("service:datasets:query")
    @GetMapping("/{id}")
    public R<DatasetsVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable String id) {
        return R.ok(iDatasetsService.queryById(id));
    }

    /**
     * 获取数据集主详细信息
     *
     * @param id 主键
     */
    @GetMapping("/getDatasetsInfo/{id}")
    public R<DatasetsVo> getDatasetsInfo(@NotNull(message = "主键不能为空")
                                             @PathVariable String id) {
        return R.ok(iDatasetsService.queryDetailsById(id));
    }


    /**
     * 新增数据集主
     */
    @SaCheckPermission("service:datasets:add")
    @Log(title = "数据集主", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody DatasetsBo bo) {
        return toAjax(iDatasetsService.insertByBo(bo));
    }

    /**
     * 修改数据集主
     */
    @SaCheckPermission("service:datasets:edit")
    @Log(title = "数据集主", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody DatasetsBo bo) {
        return toAjax(iDatasetsService.updateByBo(bo));
    }


    /**
     * 修改数据集主
     */
    @SaCheckPermission("service:datasets:edit")
    @PutMapping("/editInfo")
    public R<Void> editInfo(@Validated(EditGroup.class) @RequestBody DatasetsBo bo) {
        return toAjax(iDatasetsService.updateDatasetsByBo(bo));
    }
    /**
     * 删除数据集主
     *
     * @param ids 主键串
     */
    @SaCheckPermission("service:datasets:remove")
    @Log(title = "数据集主", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable String[] ids) {
        return toAjax(iDatasetsService.deleteWithValidByIds(Arrays.asList(ids), true));
    }

}
